import allure
import pytest

from selenium import webdriver

from utils.util import get_screen_path


@pytest.fixture(scope="session")
def drivers():
    global driver
    driver=webdriver.Chrome()
    driver.maximize_window()
    print("打开浏览器")
    yield driver
    driver.close()
    print("关闭浏览器")

@pytest.hookimpl(hookwrapper=True,tryfirst=True)
def pytest_runtest_makereport(item,call):
    out=yield
    report=out.get_result()
    print(f"{report.when}")
    print(f"{report.outcome}")
    if report.when=="call" and report.failed:
        driver.save_screenshot(get_screen_path())
        allure.attach(driver.get_screenshot_as_png(),"执行失败截图",allure.attachment_type.PNG)
